#include "service_impl.h"
#include <vector>
#include "department.h"
#include <iostream>
#include "getch.h"
#include "servicedao_file_impl.h"

using namespace std;
using namespace MH;


void ServiceImpl::addDept(void)
{
	cout << "输入要添加的部门" << endl;
	int id = 0;
	cin >> id;
	cout << "输入要添加的部门的名称" << endl;
	char name[20] = {};
	cin >> name;

	Department* de = new Department(id,name);
	m_vecDepts.push_back(*de);
	cout << "添加成功" << endl;
	sleep(2);
	getch();

}
void ServiceImpl::deleteDept(void)
{
		cout << "输入要删除的部门id" << endl;
		int id = 0;
		cin >> id;
		for(unsigned int i=0; i<m_vecDepts.size();i++)
		{
			if(m_vecDepts[i].m_nid == id)
			{
				m_vecDepts.erase(m_vecDepts.begin()+i);
				cout << "删除成功" << endl;
				getch();
				sleep(2);
				return;
			}
		}
		cout << "没有找到部门，删除失败" << endl;
		sleep(2);
		getch();
}

void ServiceImpl::listDept(void)
{
	cout << "部门id" << " " << "部门名称" << endl;
	for(unsigned int i=0; i<m_vecDepts.size();i++)
	{
		cout << m_vecDepts[i].m_nid << " " << m_vecDepts[i].m_strName << endl;
	}
	sleep(2);
}

void ServiceImpl::addEmp(void)
{
		cout << "请输入部门id：" << endl;
		int id = 0;
		cin >> id;
		for(unsigned int i=0; i<m_vecDepts.size();i++)
		{
			if(m_vecDepts[i].m_nid == id)
			{
				m_vecDepts[i].addEmp();
				break;
				
			}
		}
		cout << "没有此部门请重新输入" << endl;
		sleep(2);
}

void ServiceImpl::deleteEmp(void)
{
		cout << "请输入部门id:" << endl;
		int id = 0;
		cin >> id;
		for(unsigned int i=0; i<m_vecDepts.size();i++)
		{
			if(m_vecDepts[i].m_nid == id)
			{
				if(m_vecDepts[i].deleteEmp())
				{
					cout << "删除成功" << endl;
					sleep(2);
				}
				else
				{
					cout << "删除失败" << endl;
					sleep(2);
				}
				break;
			}
		}
		cout << "没有此部门，请重新输入" << endl;
		sleep(2);
}

void ServiceImpl::modifyEmp(void)
{
	
		cout << "请输入部门id:" << endl;
		int id = 0;
		cin >> id;
		for(unsigned int i=0; i<m_vecDepts.size();i++)
		{
			if(m_vecDepts[i].m_nid == id)
			{
				if(m_vecDepts[i].modifyEmp())
				{
					cout << "修改成功" << endl;
					sleep(2);
				}
				else
				{
					cout << "修改失败" << endl;
					sleep(2);
				}
				break;
			}
		}
		cout << "没有此部门，请重新输入" << endl;
		sleep(2);
}

void ServiceImpl::listEmp(void)
{
		cout << "请输入部门id:" << endl;
		int id = 0;
		cin >> id;
		for(unsigned int i=0; i<m_vecDepts.size();i++)
		{
			if(m_vecDepts[i].m_nid == id)
			{
				m_vecDepts[i].listEmp();
				sleep(2);
			}
		}
}

void ServiceImpl::listAllEmp(void)
{
	for(unsigned int i=0; i<m_vecDepts.size();i++)
	{
		cout << m_vecDepts[i].m_nid << " " << m_vecDepts[i].m_strName << endl;
		m_vecDepts[i].listEmp();
	}
	sleep(2);
	
}
